-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gentype: make output DCE-friendly #6508
Conversation
|
||
export type Props = { readonly s: string }; | ||
|
||
export const make: React.ComponentType<{ readonly s: string }> = ExportWithRenameBS.ExportWithRename; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript report type error on this
Property 'ExportWithRename' does not exist on type 'typeof import(".../ExportWithRename.bs")'.
Which is accurate.
That may be the intended behavior of @gentType.as
, but it doesn't actually work. If it's not a bug, I can't even fix it.
The test fails due to an unrelated bug mentioned above. |
|
||
export type record = { readonly x: number; readonly y: string }; | ||
|
||
export type firstClassModule = { readonly x: number }; | ||
|
||
export const MT_x: number = FirstClassModulesInterfaceBS.MT.x; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript report on this
error TS2339: Property 'MT' does not exist on type 'typeof import("/Users/runner/work/rescript-compiler/rescript-compiler/jscomp/gentype_tests/typescript-react-example/src/FirstClassModulesInterface.bs")'
because MT
is actually module type, so it should be handled as a type, not a value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handling first class modules appears to be a partial implementation.
The translator part is a bit new to me, I'm spending some time debugging and tracing the flow. I will make a PR in this week.
BTW bugs found here imply that it hasn't had any real users for a long time. Maybe we'll feel a bit more confident in deprecating gentype advanced features? @cristianoc |
That was never fully supported. Perhaps just delete the test? |
I'm concerned about is that if a user doesn't actually call it at runtime, but generates the type, then sees type errors from TypeScript that the user didn't get before. Is it too much to worry about? |
OK that looks better, I thought it was awkward to add a feature to deprecate |
Are there other outstanding issues after that PR? |
Some real user here. 😃 |
I think nothing left then. But let me rebase this PR first to make sure |
3e7965d
to
6c1948f
Compare
6c1948f
to
9596f55
Compare
@cristianoc ready to merge |
Great. |
@mununki could you try this on your project? |
I confirm that the gentype ouput looks intended as this PR proposes. But I have still same TS build error as below:
This issue is opened #6521 |
It was introduced by #6442 and is not directly related to this change. correct? |
The issue #6521 is related to the gentype configuration. |
Background
I recently discovered a problem while using gentype.
When using ES6 output, gentype assigns an imported namespace to a variable.
This harms DCE. ESM bundlers optimize module dependencies when they can be statically analyzed. However, if indirection such as alias variables is added, it will be deopted.
For example:
When exec
esbuild src/Module.js --bundle --format=esm --target=node18 --outfile=bundle.js
esbuild doesn't do DCE for
Dep2.js
module.This change makes gentype output to be more friendly with bundlers.
Q. What is
const ModuleBS: any = ModuleBS__Es6Import;
anyway?allowJs: true
.Q. Why
as any
is needed for every binding?Q. Why are new errors reported in
make test-gentype
after making changes?